/**
 * Copyright (c) http://www.egaoshow.ccn
 * 
 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
package cn.tworen.demou;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import net.sf.cindy.Buffer;
import net.sf.cindy.buffer.BufferFactory;

import org.apache.log4j.Logger;

/**
 * Created on  2007-1-17
 *
 * Title       : Test2.java
 * Description : 
 * 
 * @author     : LuJinYi
 * @version    : 1.0
 * @Date       : 2007-1-17
 * History     : 
 * 
 */
public class Test2 {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(Test2.class);

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		byte index = (byte)0xc3;//1100 0011 0011 1100
		logger.debug(index);
		logger.debug(index & 0xFF);
		logger.debug(Integer.toHexString(195));
		logger.debug(((byte)0x03) & ((byte)0xFF));
		BigInteger b1 = new BigInteger(new byte[]{index});
		BigInteger b2 = new BigInteger(new byte[]{01});
		BigInteger b3 = b1.add(b2);
		logger.debug(b1.toString(2));
		logger.debug(b2.toString(2));
		logger.debug(b3.toString(2));
		logger.debug(b1.not().toString(16));
		b2 = new BigInteger("11111111", 2);
		logger.debug(b2.subtract(b1.not()).intValue());
		b2 = new BigInteger("79", 10);
		byte[] datas = b2.toByteArray();
		logger.debug(datas);
		
		Buffer buffer = BufferFactory.allocate(8);
		buffer.put((byte)0x03);
		buffer.put((byte)0x00);
		buffer.put((byte)0x00);
		buffer.put((byte)0x00);
		
		Buffer buffer2 = BufferFactory.allocate(4);
		buffer2.putInt(79);
		buffer2.flip();
		byte[] datas2 = buffer2.asByteBuffer().array();
		BigInteger b4 = new BigInteger(datas2);
		logger.debug(b4.toString(16));
		logger.debug(datas2.length);
		for(int i = 0; i < datas2.length; i ++) {
			logger.debug(datas2[i]);
		}
		new Test2().testList();
		BigInteger b5 = new BigInteger("" + 195, 10);
		BigInteger b6 = new BigInteger("10000000", 2);
		logger.debug(b5.toString(2));
		b5 = b5.or(b6);
		b6 = new BigInteger("10111111", 2);
		b5 = b5.and(b6);
		logger.debug(b5.toString(2));
		
		Buffer lengthBuffer = BufferFactory.allocate(4);
		lengthBuffer.put((byte)255);
		lengthBuffer.flip();
		logger.debug(lengthBuffer.dump());
		b6 = new BigInteger("555", 10);
		logger.debug(b6.toString(16));
		logger.debug(b6.toByteArray().length);
		byte[] dd = b6.toByteArray();
		for(int i =0 ; i < dd.length; i ++){
			logger.debug(dd[i]);
		}
		String ss = "bcd";
		logger.debug(ss.substring(0, 1));
		logger.debug(ss.substring(1, 3));
		
	}
	private void testList(){
		List arg = new ArrayList();
		arg.add("test1");
		arg.add("test2");
		arg.add("test3");
		Object o;
		for(Iterator iter = arg.iterator(); iter.hasNext(); testOutList(o))
			o = iter.next();
		
	}
	private void testOutList(Object value) {
		logger.debug(value);
	}

}
